<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let fn = function(a, b) {
            return a + b
        }
        console.log(fn(1,2))
        //箭头函数
        let fn2 = (a, b) => {
            return a + b
        }
        console.log(fn2(3,4)) //调用与常规函数相同

        //1.箭头函数的this是静态的，始终指向函数声明时所在作用域的this
        function getName() {
            console.log(this.name)
        }
        let getName2 = () => {
            console.log(this.name)
        }
        
        window.name = 'Atgg'
        const school = {
            name: 'Atgg2'
        }

        //直接调用无区别
        getName()
        getName2()

        //使用call调用，即在对象内调用
        getName.call(school) //箭头函数this指向window
        getName2.call(school) //函数this指向school

        //2.箭头函数不能用作构造函数
        let Person = (name, age) => {
            this.name = name
            this.age = age
        }
        // let me = new Person('zs', 18) //报错
        // console.log(me)

        //3.箭头函数内不能用arguments
        let fn3 = ()=>{
            console.log(arguments)
        }
        //fn3() //报错

        //4.箭头函数可以简写，形参有且只有1个时刻省略()，函数体只有一行时可省略{}和return
        let pow = n => n*n
        console.log(pow(2))
    </script>
</body>
</html>